package com.wlcj.www.web.product;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;
import com.wlcj.www.model.main.Content;
import com.wlcj.www.model.product.UnfinishedProduct;
import com.wlcj.www.service.ProductService;
import com.wlcj.www.web.BaseAction;

public class ProductAction extends BaseAction{
	
	private ProductService productService = s(ProductService.class);
	public void index(){
		/**
		 * 最新标的
		 */
		List<UnfinishedProduct> products = UnfinishedProduct.dao.getNewProduct(); 
		/**
		 * 精选标的
		 */
		Map<String,List<UnfinishedProduct>> maps =  UnfinishedProduct.dao.getGoodProduct();
		// 广告位
		/**
		 * 按期限选标
		 */
		Map<String,List<UnfinishedProduct>> qixian = UnfinishedProduct.dao.getQiXian();
		/**
		 * 大家都购买了
		 */
		List<UnfinishedProduct> productsMessage = UnfinishedProduct.dao.getMessageBy();
		setAttr("productsMessage", productsMessage);
		// 广告位
		int[] guanggaoweiids = new int[]{2467,2472,2476};
		List<Content> guanggaowei = Content.dao.getListByIds(guanggaoweiids);
		setAttr("guanggaowei", guanggaowei);
		setAttr("qixian", qixian);
		setAttr("jingxuan", maps);
		setAttr("newProduct", products);
		renderJsp("prodcutIndex.jsp");
	}
	public void anshouyi(){
		/**
		 * 按收益选标
		 */
		Map<String,List<UnfinishedProduct>> income = UnfinishedProduct.dao.getIncome();
		setAttr("income", income);
		renderJsp("anshouyi.jsp");
	}
	
	public void licaijiaoliu(){
		int channel_id = getParaToInt("channel_id");
		List<Content> pic = Content.dao.getListByChannelId(channel_id, 0,1);
		List<Content> nopic = Content.dao.getListByChannelId(channel_id, 1,4);
		setAttr("pic", pic);
		setAttr("nopic", nopic);
		renderJsp("licaijiaoliu.jsp");
	}
	
	public void fangpianweiquan(){
		int channel_id = getParaToInt("channel_id");
		List<Content> pic = Content.dao.getListByChannelId(channel_id, 0,1);
		List<Content> nopic = Content.dao.getListByChannelId(channel_id, 1,4);
		setAttr("pic", pic);
		setAttr("nopic", nopic);
		renderJsp("fangpianweiquan.jsp");
	}
	
	public void headSearch(){
		// 为空搜索平台
		String lanmu = getPara("lanmu");
		String word = getPara("word");
		if("product".equals(lanmu)){//产品
			Page<UnfinishedProduct> page = productService.getPageByName(word);
			int[] guanggaoweiids = new int[]{2467,2472,2476};
			List<Content> guanggaowei = Content.dao.getListByIds(guanggaoweiids);
			setAttr("guanggaowei", guanggaowei);
			setAttr("page", page);
			setAttr("productsMessage", UnfinishedProduct.dao.getMessageBy());
			renderJsp("../productList/productList.jsp");
			//redirect("../productList/productList");
		}else if("zixun".equals(lanmu)){//资讯
			
		}else if("luntan".equals(lanmu)){//论坛
			
		}else{
			
		}
	}
	
	public void productLsit(){
		redirect("/productList");
	}
}
